#include "stdafx.h"
#include "XTempCanvas.h"

#include "DrawObjHelper.h"

XTempCanvas::XTempCanvas(XIMAGE xImage)
{
    m_XCanvas = DrawObjHelper::CreateCanvas(xImage);
    m_xOldImage = (XUIOBJECT)::SelectObject((HDC)m_XCanvas, (HGDIOBJ)xImage);
#ifdef _DEBUG
    XASSERT_URGENT(m_xOldImage != NULL, _T("XTempCanvas Failed."));
    if(m_xOldImage == NULL)
    {
        BITMAP Bmp;
        BOOL bResult = (GetObject(xImage, sizeof(Bmp), &Bmp) > 0);
        int a = 0;
    }
#endif // 
}

XTempCanvas::~XTempCanvas()
{
    if(m_XCanvas != NULL)
    {
        ::SelectObject((HDC)m_XCanvas, (HGDIOBJ)m_xOldImage);
        DrawObjHelper::DeleteCanvas(m_XCanvas);

        m_XCanvas = NULL;
        m_xOldImage = NULL;
    }
}

XTempCanvas::operator XCANVAS()
{
    return m_XCanvas;
}